//
//  YSY_SkillDetail_View.m
//  GoodManNews
//
//  Created by dllo on 16/1/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YSY_SkillDetail_View.h"

@interface YSY_SkillDetail_View()
@property (nonatomic, assign) NSInteger imageTag;

@end
@implementation YSY_SkillDetail_View

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)dealloc
{
    [_skill_B_image release];
    [_skill_E_image release];
    [_skill_Q_image release];
    [_skill_R_image release];
    [_skill_W_image release];
    [_skillNameL release];
    [_skillVideo_btn release];
    [_skillsDetailTextV release];
    [super dealloc];
}
- (void)createView {
    self.imageTag = 30001;
    NSMutableArray *arr = @[].mutableCopy;
    self.skill_B_image = [UIImageView new];
    self.skill_B_image.tag = 30001;
    self.skill_B_image.layer.borderWidth = 3;
    self.skill_B_image.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.skill_B_image.layer.masksToBounds = YES;
    
    
    
    self.skill_Q_image = [UIImageView new];
    self.skill_Q_image.tag = 30002;
    self.skill_Q_image.layer.borderWidth = 3;
    self.skill_Q_image.layer.borderColor = [[UIColor blackColor] CGColor];
    self.skill_Q_image.layer.masksToBounds = YES;
    
    
    self.skill_W_image = [UIImageView new];
    self.skill_W_image.tag = 30003;
    self.skill_W_image.layer.borderWidth = 3;
    self.skill_W_image.layer.borderColor = [[UIColor blackColor] CGColor];
    self.skill_W_image.layer.masksToBounds = YES;
    
    
    self.skill_E_image = [UIImageView new];
    self.skill_E_image.tag = 30004;
    self.skill_E_image.layer.borderWidth = 3;
    self.skill_E_image.layer.borderColor = [[UIColor blackColor] CGColor];
    self.skill_E_image.layer.masksToBounds = YES;
    
    
    self.skill_R_image = [UIImageView new];
    self.skill_R_image.tag = 30005;
    self.skill_R_image.layer.borderWidth = 3;
    self.skill_R_image.layer.borderColor = [[UIColor blackColor] CGColor];
    self.skill_R_image.layer.masksToBounds = YES;
    
    
    self.skill_B_image.backgroundColor = [UIColor yellowColor];
    self.skill_Q_image.backgroundColor = [UIColor redColor];
    self.skill_W_image.backgroundColor = [UIColor yellowColor];
    self.skill_E_image.backgroundColor = [UIColor redColor];
    self.skill_R_image.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.skill_B_image];
    [self addSubview:self.skill_Q_image];
    [self addSubview:self.skill_W_image];
    [self addSubview:self.skill_E_image];
    [self addSubview:self.skill_R_image];
    
    [arr addObject:self.skill_B_image];
    [arr addObject:self.skill_Q_image];
    [arr addObject:self.skill_W_image];
    [arr addObject:self.skill_E_image];
    [arr addObject:self.skill_R_image];
    
    [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:WIDTH / 5 leadSpacing:0 tailSpacing:0];
    [arr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.height.mas_equalTo(HEIGHT / 12);        
    }];
    
    
    
    self.skillNameL = [UILabel new];
    self.skillNameL.backgroundColor = [UIColor whiteColor];
    self.skillNameL.textAlignment = NSTextAlignmentCenter;
    self.skillNameL.font = [UIFont systemFontOfSize:20];
    self.skillNameL.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    self.skillNameL.textColor = [UIColor blueColor];
    [self addSubview:self.skillNameL];
    [self.skillNameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.skill_B_image.mas_bottom);
        make.left.equalTo(self);
//        make.width.mas_equalTo(WIDTH / 6 * 5);
        make.width.mas_equalTo(WIDTH );
        make.height.mas_equalTo(HEIGHT / 24);
    }];
//    self.skillVideo_btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.skillVideo_btn.backgroundColor = [UIColor cyanColor];
//    [self.skillVideo_btn setTitle:@"视频" forState:UIControlStateNormal];
//    [self addSubview:self.skillVideo_btn];
    
    [self.skillVideo_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.skill_B_image.mas_bottom);
        make.left.equalTo(self.skillNameL.mas_right);
        make.right.equalTo(self);
        make.height.equalTo(self.skillNameL);
    }];
    
    
    self.skillsDetailTextV = [UITextView new];
    self.skillsDetailTextV.font = [UIFont systemFontOfSize:20];
    self.skillsDetailTextV.editable = NO;
    self.skillsDetailTextV.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.skillsDetailTextV];
    [self.skillsDetailTextV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.skillNameL.mas_bottom);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self);
    }];
    
    
    self.skill_B_image.userInteractionEnabled = YES;
    self.skill_Q_image.userInteractionEnabled = YES;
    self.skill_W_image.userInteractionEnabled = YES;
    self.skill_E_image.userInteractionEnabled = YES;
    self.skill_R_image.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap_B = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.skill_B_image addGestureRecognizer:tap_B];
    [tap_B release];
    
    UITapGestureRecognizer *tap_Q = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.skill_Q_image addGestureRecognizer:tap_Q];
    [tap_Q release];
    
    UITapGestureRecognizer *tap_W = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.skill_W_image addGestureRecognizer:tap_W];
    [tap_W release];
    
    UITapGestureRecognizer *tap_E = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.skill_E_image addGestureRecognizer:tap_E];
    [tap_E release];
    
    UITapGestureRecognizer *tap_R = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.skill_R_image addGestureRecognizer:tap_R];
    [tap_R release];
}
//轻拍手势方法
- (void)tapAction:(UITapGestureRecognizer *)sender {
    if (self.imageTag != sender.view.tag) {
        UIImageView *image = [self viewWithTag:self.imageTag];
        image.layer.borderColor = [[UIColor blackColor] CGColor];
        UIImageView *currentImage = [self viewWithTag:sender.view.tag];
        currentImage.layer.borderColor  = [[UIColor whiteColor] CGColor];
    }
    self.imageTag = sender.view.tag;
    [self.delegate sendChooseInfo:sender.view.tag - 30000];
}
@end
